package com.test.last;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


public class MyAdapter extends ArrayAdapter {


    public MyAdapter(@NonNull Context context, int resource, @NonNull ArrayList<HashMap<String,String>> list) {
        super(context, resource, list);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = convertView;
        if(view == null){
            view = LayoutInflater.from(getContext()).inflate(R.layout.weather_list,parent,false);
        }       //获取需要的适配器布局，   得到适配器的基本形式

        Map<String,String> map = (Map<String, String>) getItem(position);  //传入的数据
        TextView city = (TextView) view.findViewById(R.id.city);           //获得布局中的控件
        TextView weather = (TextView) view.findViewById(R.id.weather);
        TextView temp = (TextView) view.findViewById(R.id.temp);


        city.setText(map.get("city"));           //适配器展现
        weather.setText(map.get("weather"));
        temp.setText(map.get("temp"));




        return view;
    }




}
